import java.util.Arrays;
import java.util.Comparator;

public class Solution1996 {
    public int numberOfWeakCharacters(int[][] properties) {
        Arrays.sort(properties, Comparator.comparingInt(a -> a[0]));
        int ans=0;
        int max=Integer.MIN_VALUE;
        int lazy=Integer.MIN_VALUE;
        int cur=properties[properties.length-1][0];
        for (int i=properties.length-1;i>=0;i--){
            if (properties[i][0]!=cur){
                cur=properties[i][0];
                max=lazy;
            }
            if (properties[i][1]<max){
                ans++;
            }
            lazy=Integer.max(lazy,properties[i][1]);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1996().numberOfWeakCharacters(new int[][]{{1,1},{2,1},{2,2},{1,2}}));
    }
}
